package com.easyCode.dataMock.dataGenerator;

import com.easyCode.dataMock.FieldMockInfo;
import com.mifmif.common.regex.Generex;

/**
 * @author 大忽悠
 * @create 2023/1/18 11:46
 */
public class RuleDataGenerator implements DataGenerator{
    /**
     * @param fieldMockInfo 字段信息
     * @return 返回模拟生成的data
     */
    @Override
    public String generator(FieldMockInfo fieldMockInfo) {
        try {
            Generex generex = new Generex(fieldMockInfo.getExtra()[0]);
            return generex.random();
        }catch (Exception e){
            throw new RuntimeException("正则表达式有误或者过于复杂,难以计算导致栈溢出: "+fieldMockInfo.getExtra());
        }
    }
}
